package com.chendx.behavior.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chendx.api.behavior.ApLikesBehaviorControllerApi;
import com.chendx.behavior.service.ApLikesBehaviorService;
import com.chendx.model.behavior.dtos.LikesBehaviorDto;
import com.chendx.model.behavior.pojos.ApLikesBehavior;
import com.chendx.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by chendx on 2022/3/8.
 */
@RestController
@RequestMapping("/api/v1")
public class ApLikesBehaviorController implements ApLikesBehaviorControllerApi {

    @Autowired
    private ApLikesBehaviorService apLikesBehaviorService;

    @PostMapping("/likes_behavior")
    @Override
    public ResponseResult like(@RequestBody LikesBehaviorDto dto) {
        return apLikesBehaviorService.like(dto);
    }

    @GetMapping("/like_behavior/one")
    @Override
    public ApLikesBehavior findLikeByArticleIdAndEntryId(Long articleId, Integer entryId, Short type) {
        ApLikesBehavior apLikesBehavior = apLikesBehaviorService.getOne(Wrappers.<ApLikesBehavior>lambdaQuery().eq(ApLikesBehavior::getArticleId, articleId)
                .eq(ApLikesBehavior::getEntryId, entryId).eq(ApLikesBehavior::getType, type));
        return apLikesBehavior;
    }
}